package com.xucy.springboot.designmodel.structural.Proxy.StaticProxy;

/**
 * @Author xucy
 * @Date 2019-07-28 08:58
 * @Description
 **/

public class Proxy implements TargetService {

    TargetService targetService;

    Proxy(TargetService targetService){
        this.targetService=targetService;
    }
    /**
     * 对目标类的insert方法进行加强
     *
     * @Author xucy
     * @Date 08:58 2019-07-28
     * @param
     * @return
     */
    @Override
    public void insert() {
        //对目标方法开启事务
        before();

        //目标方法的insert
        try{
            targetService.insert();

            after("提交");
        }catch (Exception e){
            after("回滚");
        }

    }


    public void before(){
        System.out.println("开启事务");
    }

    public void after(String msg){
        System.out.println(msg+"事务");
    }
}
